import datetime
import os.path
import sys
import os

from selenium.webdriver.common.by import By

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import logging

CHROME_DRIVER_PATH = "D:\\chromedriver-win64\\chromedriver-win64\\chromedriver.exe"

logging.basicConfig(level=logging.INFO)
class Driver:
    driver=""
    def __init__(self):
        options=webdriver.ChromeOptions()

        self.driver=webdriver.Chrome(service=Service(CHROME_DRIVER_PATH),options=options)
        self.driver.implicitly_wait(10)


    def GetScreeShot(self):
        dirname = datetime.datetime.now().strftime("%Y-%m-%d")
        # 判读dirname是否存在，不存在就创建文件夹
        if not os.path.exists("../images/" + dirname):
            os.mkdir("../images/" + dirname)

        filename = sys._getframe().f_back.f_code.co_name + "-" + datetime.datetime.now().strftime(
            "%Y-%m-%d-%H%M%S") + ".png"
        self.driver.save_screenshot("../images/" + dirname + "/" + filename)

blog_driver=Driver()